package com.snailframework.gateway.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author: zgadmin(zhangge)
 * @Date: 2023/2/20 下午4:28
 * @Version: 1.0.0
 */
@Slf4j
@Configuration
public class GatewayConfig {

    @Bean
    CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource source            = new UrlBasedCorsConfigurationSource();
        CorsConfiguration               corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedOriginPattern("*");
        source.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsWebFilter(source);
    }

}